import { Controller, Get, Param, Request } from "@nestjs/common";
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
import { Roles } from "src/utils/decorators/roles.guard";
import { LogService } from "./log.service";

@Controller("log")
@ApiTags("日志")
@ApiBearerAuth()
export class LogController {
  constructor(private readonly logService: LogService) {}
  @Get("list")
  list(@Request() req) {
    if (req.user.aud === "admin") {
      return this.logService.findAll();
    } else {
      const companyId = req.user.company;
      return this.logService.findByCompany(companyId);
    }
  }
  @Get("list/user/:userId")
  listByUser(@Param("userId") userId: string) {
    return this.logService.findByUser(userId);
  }

  // 列出公司id对应的所有日志列表
  @Get("list/:companyId")
  @Roles("admin")
  listByCompany(@Param("companyId") companyId: string) {
    return this.logService.findByCompany(companyId);
  }

  // 根据ID查找送货单
  @Get(":id")
  find(@Param("id") id: string) {
    return this.logService.find(id);
  }
}
